var GameData = require('../../module/GameData')();
var hero_list_Data = require('./hero_list_Data')();

cc.Class({
    extends: cc.Component,

    properties: {
        left_node: cc.Node,
        left_property: cc.Node,
        right_dsc: cc.Node,
        right_dsc_dsc: cc.Label,
        down_progress: cc.Node,
        down_btn: cc.Node,
        back_btn: cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.init();
    },
    onEnable() {
        this.back_btn.active = true;
    },
    start() {

    },
    init(data) {
        if (!data) {
            return;
        }
        let dan_icon = this.left_node.getChildByName("up").getChildByName("up");

        let hero_icon = this.left_node.getChildByName("center").getChildByName("hero_icon");
        let hero_weplon = this.left_node.getChildByName("center").getChildByName("hero_weplon");

        let dan_pro = this.left_node.getChildByName("up").getChildByName("progress_Bar");
        this.change_progress(dan_pro, data.dan_value1, data.dan_value2);
        this.left_node.getChildByName("down").getChildByName("heroName").string = data.hero_name;

        this.left_property.getChildByName("life").getChildByName("dsc").string = data.life_dsc;
        this.left_property.getChildByName("attack").getChildByName("dsc").string = data.attack_dsc;
        this.left_property.getChildByName("bullet").getChildByName("dsc").string = data.buttet_dsc;

        let life_bar = this.left_property.getChildByName("life").getChildByName("progress_Bar");
        let attack_bar = this.left_property.getChildByName("attack").getChildByName("progress_Bar");
        let bullet_bar = this.left_property.getChildByName("bullet").getChildByName("progress_Bar");
        this.change_progress(life_bar, data.dan_lifeNum1, data.dan_lifeNum2);
        this.change_progress(attack_bar, data.attackNum1, data.attackNum2);
        this.change_progress(bullet_bar, data.bulletNum1, data.bulletNum2);

        this.right_dsc.getChildByName("up").getChildByName("lock_dsc").string = data.lock_dsc;
        this.right_dsc.getChildByName("center").getChildByName("ji_neng").string = data.ji_neng;
        this.right_dsc_dsc.string = data.right_dsc_dsc;


        this.change_progress(this.down_progress, data.heroNum1, data.heroNum2);


        this.down_btn.getChildByName("dsc").string = data.need_coin;
    },
    change_progress(_progressBar, value1, value2,) {
        _progressBar.getChildByName("value").getChildByName("num1").string = value1 + "";
        _progressBar.getChildByName("value").getChildByName("num2").string = value2 + "";
        _progressBar.getComponent(cc.ProgressBar).progress = value1 / value2;
    },
    upgrade_btn() {

    },
    back() {
        if (this.node.active) {
            GameData.hero_layer.title.string = hero_list_Data.title;
            cc.find("Canvas/main").active = true;
            this.node.active = false;
            // this.back_btn.active = false;
        } else {
            cc.director.loadScene("game_start");
        }
    },
    // update (dt) {},
});
